<?php

namespace app\controller\web;

use app\service\ProjectInfoService;
use app\validate\PageValidate;
use app\validate\ProjectInfoValidate;
use share\utils\Helper;

class ProjectInfoController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new ProjectInfoValidate();
    }

    /**
     * 新增项目信息
     */
    public function add_action(){
        $input = $this->check();
        $data = ProjectInfoService::addProject($input);
        return self::ok($data);
    }

    /**
     * 修改项目信息
     */
    public function edit_action(){
        $input = $this->check();
        $data = ProjectInfoService::updateProject($input);
        return self::ok($data);
    }

    /**
     * 删除项目信息
     */
    public function del_action(){
        $input = $this->check();
        $data = ProjectInfoService::delProject($input['projectId']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = [];       
        $data = ProjectInfoService::getListInfo($input,$page);
        $data = Helper::arrayListReplaceKey($data,[
            'project_id' => 'projectId',
            'project_name' => 'projectName',
            'create_time' => 'createTime',
            'update_time' => 'updateTime',
        ]);
        $total = ProjectInfoService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }


}